//
//  SISSEscrowAccountInfoViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/12/25.
//  Copyright © 2018 优房网. All rights reserved.
//

#import "SISSEscrowAccountInfoViewController.h"
#import "SISSTitleView.h"
#import "SISSShowView.h"
#import "SISSChooseView.h"
#import "SISSEscrowAccountShowViewController.h"
#import "SISSNetworkingManager+HouseProgress.h"
#import "SISSHouseProgressModel.h"

@interface SISSEscrowAccountInfoViewController ()<SISSChooseViewDelegate>

/// topTitleView
@property (weak, nonatomic) SISSTitleView *topTitleView;
@property (weak, nonatomic) SISSShowView *accountStatusView;
@property (weak, nonatomic) SISSChooseView *accountDetailView;
@property (weak, nonatomic) SISSShowView *bankView;
@property (weak, nonatomic) SISSShowView *accountNameView;
@property (weak, nonatomic) SISSShowView *accountNumView;
@property (weak, nonatomic) SISSShowView *accountView;
///
@property (weak, nonatomic) UILabel *bottomLabel;

@property (strong, nonatomic) SISSEscrowAccountInfoModel *ecrowAccountInfoModel;
@end

@implementation SISSEscrowAccountInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"资金监管账户信息";
    
    [self requestData];
}

#pragma mark - SISSChooseViewDelegate
- (void)clickChooseActionWithChooseView:(SISSChooseView *)chooseView {
    SISSEscrowAccountShowViewController *vc = [[SISSEscrowAccountShowViewController alloc] init];
    vc.houseProgressModel = self.houseProgressModel;
    vc.houseProgressRecordInfoModel = self.houseProgressRecordInfoModel;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)requestData {
    [kNetworkManager requestFundSupervisionInfoWithAhbpId:self.houseProgressModel.ahbpId success:^(SISSEscrowAccountInfoModel *ecrowAccountInfoModel) {
        self.ecrowAccountInfoModel = ecrowAccountInfoModel;
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (void)setEcrowAccountInfoModel:(SISSEscrowAccountInfoModel *)ecrowAccountInfoModel {
    _ecrowAccountInfoModel = ecrowAccountInfoModel;
    self.accountStatusView.rightStr = @"";
    self.bankView.rightStr = ecrowAccountInfoModel.bank;
    self.accountNameView.rightStr = ecrowAccountInfoModel.accountName;
    self.accountNumView.rightStr = ecrowAccountInfoModel.accountNum;
    self.accountView.rightStr = ecrowAccountInfoModel.amount;
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    SISSTitleView *topTitleView = [[SISSTitleView alloc] init];
    topTitleView.titleStr = @"资金监管信息";
    [self.view addSubview:topTitleView];
    self.topTitleView = topTitleView;
    
    SISSShowView *accountStatusView = [[SISSShowView alloc] init];
    accountStatusView.isShowBottomLine = YES;
    accountStatusView.leftStr = @"监管帐户状态";
    [self.view addSubview:accountStatusView];
    self.accountStatusView = accountStatusView;
    
    SISSChooseView *accountDetailView = [[SISSChooseView alloc] init];
    accountDetailView.leftStr = @"监管帐户详情";
    accountDetailView.isShowBottomLine = YES;
    accountDetailView.delegate = self;
    [self.view addSubview:accountDetailView];
    self.accountDetailView = accountDetailView;
    
    SISSShowView *bankView = [[SISSShowView alloc] init];
    bankView.leftStr = @"监管银行";
    bankView.isShowBottomLine = YES;
    [self.view addSubview:bankView];
    self.bankView = bankView;
    
    SISSShowView *accountNameView = [[SISSShowView alloc] init];
    accountNameView.leftStr = @"监管帐户姓名";
    accountNameView.isShowBottomLine = YES;
    [self.view addSubview:accountNameView];
    self.accountNameView = accountNameView;
    
    SISSShowView *accountNumView = [[SISSShowView alloc] init];
    accountNumView.leftStr = @"监管帐户账号";
    accountNumView.isShowBottomLine = YES;
    [self.view addSubview:accountNumView];
    self.accountNumView = accountNumView;
    
    SISSShowView *accountView = [[SISSShowView alloc] init];
    accountView.leftStr = @"帐户余额";
    accountView.isShowBottomLine = YES;
    [self.view addSubview:accountView];
    self.accountView = accountView;
    
    UILabel *bottomLabel = [UILabel yyr_labelWithText:@"页面信息由监管银行提供，实际信息请以银行核实为准；" fontSize:15 textColor:SECONDARY_TEXT_COLOR];
    bottomLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:bottomLabel];
    self.bottomLabel = bottomLabel;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    [self.topTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.mas_topLayoutGuideBottom);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.accountStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.topTitleView.mas_bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.accountDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.accountStatusView.mas_bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.bankView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.accountDetailView.mas_bottom).offset(globelMargin);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.accountNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.bankView.mas_bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.accountNumView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.accountNameView.mas_bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.accountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.accountNumView.mas_bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.accountView.mas_bottom).offset(2 * globelMargin);
        make.centerX.equalTo(weakSelf.view);
        make.left.equalTo(weakSelf.view).offset(2 * globelMargin).priority(999);
        make.right.equalTo(weakSelf.view).offset(-2 * globelMargin).priority(999);
    }];
}

@end
